﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace jTCodeGenerate
{
    public class jTHelper
    {
        public static string GetFileJson(string filepath)
        {
            string json = string.Empty;
            using (FileStream fs = new FileStream(filepath, FileMode.Open, System.IO.FileAccess.Read, FileShare.ReadWrite))
            {
                using (StreamReader sr = new StreamReader(fs, Encoding.UTF8))
                {
                    json = sr.ReadToEnd().ToString();
                }
            }
            return json;
        }

        public static void GetWriteJson(string content, string path, string fileName)
        {
            if (Directory.Exists(path))
                Directory.CreateDirectory(path);
            var filePath = Path.Combine(path, fileName);
            if (!File.Exists(filePath))
                return;
            using (FileStream fs = new FileStream(Path.Combine(path, fileName), FileMode.Open, System.IO.FileAccess.Write, FileShare.ReadWrite))
            {
                using (StreamWriter sr = new StreamWriter(fs, Encoding.UTF8))
                {
                    var c = Encoding.UTF8.GetBytes(content);
                    sr.Write(content);
                }
            }
        }
    }
}
